/**
 * 
 */
package com.kth.subtranslator.driver;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

import com.kth.subtranslator.ITranslateDriver;
import com.kth.subtranslator.ITranslateDriverConfiguration;

/**
 * @author Kevin Thackray
 *
 */
public abstract class AbstractTranslateDriver implements ITranslateDriver {
	
	private final AtomicBoolean stopFlag = new AtomicBoolean(false);

	protected List<String> chunkString(String text, int chunkSize) {
		int cur = 0;
		List<String> chunked = new ArrayList<String>();
		while(cur < text.length()) {
			int textToCut = text.substring(cur).length() >= chunkSize?chunkSize:text.substring(cur).length();
			chunked.add( text.substring(cur, cur+textToCut) );
			cur+=textToCut;
		}
		return chunked;
	}
	
	/* (non-Javadoc)
	 * @see com.kth.subtranslator.ITranslateDriver#stop()
	 */
	@Override
	public void stop() {
		stopFlag.set(true);
	}
	
	public boolean isStopped() {
		boolean isStopped = stopFlag.get();
		if (isStopped) {
			stopFlag.set(false);
			return true;
		}
		else {
			return false;
		}
//		return stopFlag.getAndSet( stopFlag.get()?true:false );
	}
	
	/* (non-Javadoc)
	 * @see com.kth.subtranslator.ITranslateDriver#getConfiguration()
	 */
	@Override
	public ITranslateDriverConfiguration getConfiguration() {
		return null;
	}

}